<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>单例模式</title>
    <script>
        let singleTon=(function(){
            let instance=null;
            class DBTool{
                constructor(name,age){
                    this.name=name;
                    this.age=age;
                }
            };
            return {
                getDBTool(){
                    if(instance==null){
                        instance=new DBTool("iboy",20);
                    }
                    return instance;
                }
            }
        })();
        console.log(singleTon.getDBTool());
        console.log(singleTon.getDBTool());
        console.log(singleTon.getDBTool()===singleTon.getDBTool());
    </script>
</head>
<body>
    
</body>
</html>